package org.jetnuke.blocks;

import javax.servlet.http.HttpServletRequest;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IBlock;
import org.jetnuke.common.IBlockInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.dao.ModuleDAO;

public class Modules implements IBlock {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.common.IBlock#serviceBlock(javax.servlet.http.HttpServletRequest,
	 *      javax.sql.DataSource, org.apache.velocity.VelocityContext,
	 *      org.jetnuke.common.IBlockInfo)
	 */
	public void serviceBlock(HttpServletRequest req, VelocityContext vc,
			IBlockInfo blockInfo, IUserInfo userInfo, IAdminInfo adminInfo)
			throws Exception {
		ModuleDAO mm=DataAccessDriver.getInst().newModulesDAO();
		//Criteria crt = new Criteria();
		//crt.add(modulesPeer.ACTIVE, 1);
		//crt.add(modulesPeer.INMENU, 1);
		//crt.addAscendingOrderByColumn(modulesPeer.TITLE);
		vc.put("rows", mm.selectAllActiveInMenu() );

		if (adminInfo != null && adminInfo.IsSuperUser()) {
			//crt = new Criteria();
			//crt.add(modulesPeer.ACTIVE, 1, Criteria.NOT_EQUAL);
			vc.put("inactiverows", mm.selectAllInactive());// modulesPeer.doSelect(crt));

			//crt = new Criteria();
			//crt.add(modulesPeer.ACTIVE, 1);
			//crt.add(modulesPeer.INMENU, 1, Criteria.NOT_EQUAL);
			vc.put("invisiblerows", mm.selectAllActiveNotMenu());// modulesPeer.doSelect(crt));
		}
	}

}
